﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.ComponentModel;

namespace ArmoryViewer
{
    class ResultSorter : ListViewCustomComparer 
    {
        public override int Compare(object x, object y)
        {
            try
            {
                Dictionary<string, string> xc = (Dictionary<string, string>)x;
                Dictionary<string, string> yc = (Dictionary<string, string>)y;

                string valX, valY;
                valX = valY = string.Empty;
                int result = 0;

                foreach (string sortColumn in GetSortColumnList())
                {
                    string path = sortColumn.Replace("[", "").Replace("]", "");
                    valX = xc[path];
                    valY = yc[path];

                    if (sortColumns[sortColumn] == ListSortDirection.Ascending)
                        result = string.Compare(valX, valY);
                    else
                        result = (-1) * string.Compare(valX, valY);

                    if (result != 0) break;
                    else continue;
                }
                return result;
            }
            catch(Exception)
            {
                return 0;
            }
        }
    }
}
